#include<iostream>
using namespace std;

const int N=2e5+10;
int arr[N];
int n,m;

int fd(int x)
{
	return arr[x]==x? x: fd(arr[x]);
}

void same(int x, int y)
{
	if(fd(x) == fd(y)) cout<<"Y"<<endl;
	else cout<<"N"<<endl;
}

void un(int x, int y)
{
	arr[fd(x)] = fd(y);
}

int main()
{
	cin>>n>>m;
	for(int i=1; i<=n; i++)
	{
		arr[i]=i;
	}
	
	while(m--)
	{
		int z; cin>>z;
		int x, y; cin>>x>>y;
		if(z==1) un(x, y);
		if(z==2) same(x, y);
	}
	
	return 0;
 } 
